
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;
using BTKERP.Model.Web;

namespace BTKERP.DAL
{
	#region RequisitionDeliveryMasterDAL
	public class RequisitionDeliveryMasterDAL : DBContext
	{
		public List<RequisitionDeliveryMaster> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDeliveryMastersSelectAll");
            return GetEntityList<RequisitionDeliveryMaster>(cmd);
        }

        public RequisitionDeliveryMaster GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDeliveryMasterSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<RequisitionDeliveryMaster>(cmd);
        }

		public List<RequisitionDeliveryMaster> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDeliveryMasterSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<RequisitionDeliveryMaster>(cmd);
        } 
		
        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDeliveryMasterDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public RequisitionDeliveryMaster UpdateById(
		Guid paramId,string paramDOCode,DateTime paramDeliveryDate,int paramResuisitionId,decimal paramDeliveryValue,DateTime paramDeliveredOn,
		int paramDeliveredBy,int paramReceivedBy,decimal paramReceivedValue,string paramStatus,string paramUpdatedBy,DateTime paramUpdateOn)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDeliveryMasterUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@DOCode", paramDOCode);
			cmd.AddParameter("@DeliveryDate", paramDeliveryDate);
			cmd.AddParameter("@ResuisitionId", paramResuisitionId);
			cmd.AddParameter("@DeliveryValue", paramDeliveryValue);
			cmd.AddParameter("@DeliveredOn", paramDeliveredOn);
			cmd.AddParameter("@DeliveredBy", paramDeliveredBy);
			cmd.AddParameter("@ReceivedBy", paramReceivedBy);
			cmd.AddParameter("@ReceivedValue", paramReceivedValue);
			cmd.AddParameter("@Status", paramStatus);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            cmd.AddParameter("@UpdatedOn", DateTime.Now);
            return GetSingleEntity<RequisitionDeliveryMaster>(cmd);
        }


        public List<RequisitionDeliveryMaster> search(string houseId, string requId, string doNo, string requeBy, int status)
        {
            ExSQLCommand cmd = new ExSQLCommand("SearchDOMaster");
            cmd.AddParameter("@houseId", new Guid(houseId));
            if (!string.IsNullOrEmpty(requId))
            {
                cmd.AddParameter("@reqCode", requId);
            }

            if (!string.IsNullOrEmpty(doNo))
            {
                cmd.AddParameter("@doNo", doNo);
            }

            if (!string.IsNullOrEmpty(requeBy))
            {
                cmd.AddParameter("@requestBy", requeBy);
            }
            cmd.AddParameter("@status", status);
            return GetEntityList<RequisitionDeliveryMaster>(cmd);
        }

        public List<ItemCountModel> GetDOMasterCountByStatus()
        {
            ExSQLCommand cmd = new ExSQLCommand("GetDOMasterInfo");
            return GetEntityList<ItemCountModel>(cmd);
        }
    }
	#endregion
}
